package com.codes.core.common.result;

import java.io.Serializable;

public class Result<T> implements Serializable {

    private int code;
    private String msg;
    private T data;
    private int count;


    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Result(int code, String msg, T data, int count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    public static <T> Result pages(T data, int count){
        return  new Result(ResultCode.PAGES.getCode(),ResultCode.PAGES.getMsg(),data,count);
    }
    public static <T> Result pages(String msg, T data, int count){
        return  new Result(ResultCode.PAGES.getCode(),msg,data,count);
    }

    public static <T> Result success(){
        return Result.success(ResultCode.SUCCESS.getMsg());
    }

    public static <T> Result success(T data){
        return  new Result(ResultCode.SUCCESS,data);
    }
    public static <T> Result success(String msg){
        return  Result.success(msg,null);
    }
    public static <T> Result success(String msg,T data){
        return  new Result(ResultCode.SUCCESS.getCode(),msg,data);
    }

    public static <T> Result failed(){
        return new Result(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMsg());
    }
    public static <T> Result validateFailed(){
        return Result.failed( ResultCode.VALIDATE_FAILED);
    }
    public static <T> Result failed(T data){
        return  new Result(ResultCode.FAILED,data);
    }
    public static <T> Result failed(String msg,T data){
        return  new Result(ResultCode.FAILED.getCode(),msg,data);
    }
    public static <T> Result failed(String msg ){
        return  Result.failed(msg,0);
    }
    public static <T> Result error(){
        return new Result(ResultCode.ERROR.getCode(),ResultCode.ERROR.getMsg());
    }
    public static <T> Result error(T data){
        return new Result(ResultCode.ERROR.getCode(),ResultCode.ERROR.getMsg(),data);
    }
    public Result() {
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(ResultCode resultCode,T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data=data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
